    <!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('新闻(文章新闻,视频新闻)列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>类型</label>
                                <select name="type" th:with="type=${@dict.getType('news_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>标题：</label>
                                <input type="text" name="title"/>
                            </li>
                            <li>
                                <label>作者：</label>
                                <input type="text" name="author"/>
                            </li>
<!--                            <li class="select-time">-->
<!--                                <label>发布时间：</label>-->
<!--                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginReleaseAt]"/>-->
<!--                                <span>-</span>-->
<!--                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endReleaseAt]"/>-->
<!--                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="jiaqin:news:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="jiaqin:news:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="jiaqin:news:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="jiaqin:news:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('jiaqin:news:edit')}]];
        var removeFlag = [[${@permission.hasPermi('jiaqin:news:remove')}]];
        var typeDatas = [[${@dict.getType('news_type')}]];
        var newsClass = [[${@newsClassService.selectNewsClassList()}]];
        var prefix = ctx + "jiaqin/news";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "新闻(文章新闻,视频新闻)",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'type',
                    title: '类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(typeDatas, value);
                    }
                },
                {
                    field: 'newsClassId',
                    title: '新闻分类',
                    formatter: function(value, row, index) {
                        for (b = 0;b<newsClass.length;b++){
                            if(newsClass[b].id == value){
                                return "<span>"+newsClass[b].name+"</span>";
                            }
                        }
                        return '';
                    }
                },
                {
                    field: 'title',
                    title: '标题'
                },
                {
                    field: 'author',
                    title: '作者'
                },
                {
                    field: 'articleCovers',
                    title: '文章封面',
                    formatter: function(value, row, index) {
                        if(row.articleCovers == null||row.articleCovers == ""){
                            return "无文章封面"
                        }

                        var arr = row.articleCovers.split(",");
                        var astr = "";
                        for (q = 0;q<arr.length;q++){
                            astr = astr + "<img src='"+arr[q]+"' onclick='showImg(\""+arr[q]+"\")' style='width: 25px;'/>";
                        }
                        return astr
                    }
                },
                {
                    field: 'articleContent',
                    title: '文章内容',
                    formatter: function(value, row, index) {
                        if(row.articleContent == null||row.articleContent == ""){
                            return "无文章内容"
                        }
                        return "<div style='color: #18d6ff')'>请编辑查看</div>"
                    }
                },
                {
                    field: 'videoCover',
                    title: '视频封面',
                    formatter: function(value, row, index) {
                        if(row.videoCover == null||row.videoCover == ""){
                            return "无视频封面"
                        }
                        return "<img src='"+row.videoCover+"' width='50px;' onclick='showImg(\""+row.videoCover+"\")'>";
                    }
                },
                {
                    field: 'videoUrl',
                    title: '视频',
                    formatter: function(value, row, index) {
                        if(row.videoUrl == null||row.videoUrl == ""){
                            return "无视频地址"
                        }
                        return "<div style='color: #ff3b25' onclick='showVideo(\""+row.videoUrl+"\")'>点击查看视频</div>"
                    }
                },
                {
                    field: 'numSee',
                    title: '浏览量',
                    sortable: true
                },
                    {
                        field: 'likes',
                        title: '点赞量',
                        sortable: true
                    },
                    {
                        field: 'commentNum',
                        title: '评论量',
                        sortable: true
                    },
                    {
                        field: 'complaintNum',
                        title: '举报数',
                        sortable: true
                    },
                {
                    field: 'releaseAt',
                    title: '发布时间',
                    sortable: true
                },
                {
                    field: 'sort',
                    title: '排序',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        //展示图片
        function showImg(imgUrl) {
            console.log(imgUrl);
            $.modal.alert("<img src='"+imgUrl+"' style='width: 600px; text-align: center;'/>",null,"800","500");
        }
        //展示视频
        function showVideo(videoUrl) {
            console.log(videoUrl);
            // if(videoUrl.indexOf("iframe") == -1){
            //     $.modal.alert("<video src='"+videoUrl+"' controls='controls' width='400' />",null,"800","500");
            // }
            // else{
                $.modal.alert("<iframe src='"+videoUrl+"' scrolling='no' border='0' frameborder='no' framespacing='0' allowfullscreen='true' width='750' height='360'> </iframe>",null,"800","500");
            // }

        }

    </script>
</body>
</html>
